<?php
	require_once 'bootstrap.php';
	//var_dump($_SESSION);
	
	if($_SESSION['user']==NULL){
		if(isset($_POST['name'])&&isset($_POST['pass'])){
			global $db;
			$query = $db->select('dbusers',array('name'=>$_POST['name'],'pass'=>$_POST['pass']));		
			$rs = $db->db_fetch_array($query);

			if($rs['NAME']!=null){
				//echo 'validate true!!!';
				$_SESSION['user'] = $_POST['name'];
				setcookie("user", $_POST['name'], time()+3600); 
				//var_dump($_SESSION);
				header('Location: firstlevel.php');
			} else{
				header('Location: index.php?error=1');
			}
		}
		else {
			//echo 'no value set';
			header('Location: index.php?error=0');
		}
	}
	
	else {
		//echo 'session exits';
		header('Location: firstlevel.php');
	}
?>